/*
 * Copyright (c) 2019 - 2020 IoT Company of Midea Group.
 *
 * File Name 	    : 
 * Description	    : Module OTA HAL adaptor
 *
 * Version	        : v0.1
 * Author			: 
 * Date	            : 2019/09/15  refactoring
 * History	        : 
 */

#ifndef __MS_HAL_OTA_H__
#define __MS_HAL_OTA_H__

/**
 * !!! please see the config.mk to make sure your chip whether had those function !!!
 * MS_CONFIG_OTA_SUPPORT
 * !!! if not, do not adapter following interfaces
 */

#include "ms_hal.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef MS_CONFIG_OTA_SUPPORT

/** MS_OTA_RES_TYPE_E brief:
*  These types are only applicable to ASR, other platforms need to be adapted.
*  Type-2 + Type-3 means Type-0.
*  The firmware cannot be verified repeatedly.
*/
typedef enum {
	MS_OTA_FINISH,          // 0: Verify firmware and do upgrade.
	MS_OTA_BREAKPOINT,      // 1: Breakpoint continuation.
	MS_OTA_VERIFY_ONLY,     // 2: Verify firmware only.
	MS_OTA_FINISH_NOVERIFY, // 3: Upgrade only.
}MS_OTA_RES_TYPE_E;

typedef enum {
	MS_OTA_REGISTER,
	MS_OTA_INIT,
}MS_OTA_INIT_TYPE_E;

/**
 * @brief 	  module ota init
 * @param[in] res_type, init type
 * @return if successly, return MS_HAL_RESULT_SUCCESS
 */
ms_hal_result_t ms_hal_ota_init(void);

/**
 * @brief 	  module ota deinit
 * @param[in] res_type, deinit type
 * @return if successly, return MS_HAL_RESULT_SUCCESS
 */
ms_hal_result_t ms_hal_ota_deinit(void);

/**
 * @brief 	   write ota firmware
 * @param[in]  off_set, off_set pointer, write to where
 * @param[in]  in_buf, in_buf pointer, the writen data stored in out_buf
 * @return if  successly, return MS_HAL_RESULT_SUCCESS
 */
ms_hal_result_t ms_hal_ota_write(int *off_set, char *in_buf, int in_buf_len);

/**
 * @brief 	   read ota partition data
 * @param[in]  off_set, off_set pointer, read form where
 * @param[out] out_buf, out_buf pointer, the read data stored in out_buf
 * @return if  successly, return MS_HAL_RESULT_SUCCESS
 */
ms_hal_result_t ms_hal_ota_read(int *off_set, char *out_buf, int out_buf_len);

/**
 * @brief 	  ota boot
 * @param[in] res_type, boot type
 * @return if successly, return MS_HAL_RESULT_SUCCESS
 */
ms_hal_result_t ms_hal_ota_boot(uint8_t res_type);

/**
 * @brief     after download success, need to setBootSetting(for Hi3861)
 * @param     null
 * @return    if successly ,return MS_HAL_RESULT_SUCCESS
 */
ms_hal_result_t ms_hal_ota_set_boot_settings(void);

/**
 * @brief 	   get module ota partition info: start address, size
 * @param[out] info, info struct contains partition_start_addr and uint32_t partition_length
 * @return if  successly, return MS_HAL_RESULT_SUCCESS
 */
ms_hal_result_t ms_hal_ota_get_partition_info(ms_hal_logic_partition_t *info);

#endif /* MS_CONFIG_OTA_SUPPORT */

#ifdef __cplusplus
}
#endif

#endif //__MS_HAL_OTA_H__

